const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");

function resolve(dir) {
  return path.resolve(__dirname, dir);
}

module.exports = {
  //指定构建环境
  mode: "development",
  //入口
  entry: {
    app: "./src/index"
  },
  //出口
  output: {
    path: resolve("./dist"),
    filename: "js/[name].[hash:8].js",
    publicPath: "/" //打包后的资源访问路径前缀
  },
  //模块
  module: {},
  //插件
  plugins: [
    new HtmlWebpackPlugin({
      filename: resolve("./dist/index.html"), //模板生成的路径
      template: "./public/index.html", //模板的位置
      inject: true, //script标签位于html文件的body底部
      hash: true, //在打包的资源插入html会加上hash
      //对html文件进行压缩
      minify: {
        removeComments: true, //删除注释
        collapseWhitespace: true, //压缩空格
        removeAttributeQuotes: true //去除标签的引号
      }
    })
  ],
  //开发环境本地启动的服务配置
  devServer: {}
};
